package com.ggqq.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2//开启Swagger2
public class SwaggerConfig {

    //多个分组
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("group1");
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("group2");
    }
    @Bean
    public Docket docket3(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("group3");
    }



    //配置Swagger的Docket的bean实例
    @Bean
    public Docket docket(Environment environment){

       //设置要显示的Swagger环境
        Profiles profiles = Profiles.of("dev","test");
        //获取项目的环境：
        boolean flag = environment.acceptsProfiles(profiles);


        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("天才小熊猫")
                .enable(flag)//swagger开关，true为开
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ggqq.swagger.controller"))//RequestHandlerSelectors配置要扫描接口的方式//basePackage指定要扫描的包
                //.paths(PathSelectors.ant("/ggqq/**"))//paths过滤什么路径
                .build();
    }

    //配置Swagger信息
    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("ggqq", "https://blog.csdn.net/Mcdull__?spm=1001.2014.3001.5343", "30252579055@11.com");
        return new ApiInfo(
               "天才小熊猫的Api文档",
               "路漫漫其修远兮，吾将上下而求索",
               "1.0",
               "https://blog.csdn.net/Mcdull__?spm=1001.2014.3001.5343",
                contact,
               "Apache 2.0",
               "http://www.apache.org/licenses/LICENSE-2.0",
               new ArrayList()
       );
    }
}
